import React, { Component } from 'react';
import { inject, observer } from 'mobx-react';
import PropTypes from 'prop-types';
import {Helmet} from 'react-helmet';
import axios from 'axios';
import appState from '../../store/app-state';


@inject('appState')
@observer
export default class News extends Component {
  constructor() {
    super();
    this.changeName = this.changeName.bind(this);
  }

  componentDidMount() {
    // do something here
  }

  bootstrap() {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        this.props.appState.name = 'AAAAAAAA';
        resolve(true);
      })
    })
    // return new Promise((resolve, reject) => {
    //   axios.post('http://192.168.30.166:8889/c/orders/base/basicEnum', {}).then(res => {
    //     if (res.status === 200 && res.data.msg === 'success') {
    //       this.props.appState.getPorts(res.data.data);
    //     }
    //     resolve(true);
    //   }).catch(err => {
    //     reject(err)
    //   })
    // })
  }

  changeName(e) {
    this.props.appState.changeName(e.target.value)
  }

  render() {
    return (
      <div>
        新闻列表页
        <Helmet>
          <title>ABCD</title>
          <meta name="description" content="description" />
        </Helmet>
        {this.props.appState.name}
      </div>
    )
  }
}

News.propTypes = {
  appState: PropTypes.instanceOf(appState),
}
